package com.futuristik.modes;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer10;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Image.Scaling;

public class MapMenu extends ArkitekMode implements InputProcessor {

	ImmediateModeRenderer10 renderer;

	Stage ui;

	public MapMenu (Game game) {
		super(game);
	}

	@Override
	public void show () {
		
		ui = new Stage(480, 320, true);
		
		Image background = new Image(new TextureRegion(new Texture(Gdx.files.internal("data/background2.png"))), Scaling.none);
		Image newGameButton = new Image(new TextureRegion(new Texture(Gdx.files.internal("data/menu2.png")), 22, 157, 278, 37), Scaling.none);
		
		background.y = 320-512;
		
		newGameButton.y = ui.height() - 130;
		newGameButton.x = 90;
		
		ui.addActor(background);
		ui.addActor(newGameButton);
				
		/*
		batch = new SpriteBatch();
		batch.getProjectionMatrix().setToOrtho2D(0, 0, 320, 480);
		*/
		
		Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
		renderer = new ImmediateModeRenderer10();	
		Gdx.input.setInputProcessor(this);	
	}
	
	@Override
	public void render (float deltaTime) {
		GL10 gl = Gdx.graphics.getGL10();
		gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		
		ui.draw();
	}

	@Override
	public void pause () {
	}

	@Override
	public void resume () {
	}

	@Override
	public void dispose () {
	}

	@Override
	public void hide () {
		System.out.println("dispose main menu");
		renderer.dispose();
		ui.clear();
		ui.dispose();
	}

	@Override
	public boolean keyDown(int keycode) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean keyUp(int keycode) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean keyTyped(char character) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDown(int x, int y, int pointer, int button) {
		Vector2 stageTouch = new Vector2();
		ui.toStageCoordinates(x, y, stageTouch);
		Actor hitActor = ui.hit(stageTouch.x, stageTouch.y);
				
		if (hitActor == null) return false;
		if (hitActor.name.startsWith("newGame"))
			game.setScreen(new Play(game));
		ui.touchUp(x, y, pointer, button);
		
		return true;
	}

	@Override
	public boolean touchUp(int x, int y, int pointer, int button) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDragged(int x, int y, int pointer) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchMoved(int x, int y) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean scrolled(int amount) {
		// TODO Auto-generated method stub
		return false;
	}

}
